#!/usr/bin/env node

import Koa        from 'koa';
import bodyParser from 'koa-bodyparser';
import cors       from "kcors";
import Router     from "koa-router";

import restify from './middleware/restify';
import rTest   from './router/test';
import config  from '../config';
import logger  from "./base/log";

import {initMongo} from './base/mongo';

const env  = process.env.NODE_ENV || 'local';
const opts = config[env];
logger(module.filename).info('Koa Server start environment: ' + env.toUpperCase(), '; port : ' + opts.port);
initMongo(opts.mongo_url);

const app = new Koa();

app.use(cors());
app.use(bodyParser());
app.use(restify());

// router
const rPublic = new Router({prefix: '/api'});
rPublic.use('/test', rTest().routes());
app.use(rPublic.routes());

app.listen(opts.port);

